home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-PPC / BYTEORDE.{_3 < prev    next >
Text File  |  1999-09-17  |  2KB  |  89 lines

  1. #ifndef _PPC_BYTEORDER_H
  2. #define _PPC_BYTEORDER_H
  3.  
  4. /*
  5.  *  $Id: byteorder.h,v 1.14 1998/08/12 05:07:12 paulus Exp $
  6.  */
  7.  
  8. #include <asm/types.h>
  9.  
  10. #ifdef __GNUC__
  11.  
  12. extern __inline__ unsigned ld_le16(volatile unsigned short *addr)
  13. {
  14.     unsigned val;
  15.  
  16.     __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
  17.     return val;
  18. }
  19.  
  20. extern __inline__ void st_le16(volatile unsigned short *addr, unsigned val)
  21. {
  22.     __asm__ __volatile__ ("sthbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
  23. }
  24.  
  25. extern __inline__ unsigned ld_le32(volatile unsigned *addr)
  26. {
  27.     unsigned val;
  28.  
  29.     __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
  30.     return val;
  31. }
  32.  
  33. extern __inline__ void st_le32(volatile unsigned *addr, unsigned val)
  34. {
  35.     __asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
  36. }
  37.  
  38. /* alas, egcs sounds like it has a bug in this code that doesn't use the
  39.    inline asm correctly, and can cause file corruption. Until I hear that
  40.    it's fixed, I can live without the extra speed. I hope. */
  41. #if !(__GNUC__ >= 2 && __GNUC_MINOR__ >= 90)
  42. #if 0
  43. #  define __arch_swab16(x) ld_le16(&x)
  44. #  define __arch_swab32(x) ld_le32(&x)
  45. #else
  46. static __inline__ __const__ __u16 ___arch__swab16(__u16 value)
  47. {
  48.     __u16 result;
  49.  
  50.     __asm__("rlwimi %0,%1,8,16,23"
  51.         : "=r" (result)
  52.         : "r" (value), "0" (value >> 8));
  53.     return result;
  54. }
  55.  
  56. static __inline__ __const__ __u32 ___arch__swab32(__u32 value)
  57. {
  58.     __u32 result;
  59.  
  60.     __asm__("rlwimi %0,%1,24,16,23\n\t"
  61.         "rlwimi %0,%1,8,8,15\n\t"
  62.         "rlwimi %0,%1,24,0,7"
  63.         : "=r" (result)
  64.         : "r" (value), "0" (value >> 24));
  65.     return result;
  66. }
  67. #define __arch__swab32(x) ___arch__swab32(x)
  68. #define __arch__swab16(x) ___arch__swab16(x)
  69. #endif /* 0 */
  70.  
  71. #endif
  72.  
  73. /* The same, but returns converted value from the location pointer by addr. */
  74. #define __arch__swab16p(addr) ld_le16(addr)
  75. #define __arch__swab32p(addr) ld_le32(addr)
  76.  
  77. /* The same, but do the conversion in situ, ie. put the value back to addr. */
  78. #define __arch__swab16s(addr) st_le16(addr,*addr)
  79. #define __arch__swab32s(addr) st_le32(addr,*addr)
  80.  
  81. #endif /* __GNUC__ */
  82.  
  83. #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  84. #define __BYTEORDER_HAS_U64__
  85. #endif
  86. #include <linux/byteorder/big_endian.h>
  87.  
  88. #endif /* _PPC_BYTEORDER_H */
  89.